package com.btr.uimeter.config;

import java.awt.Component;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.AbstractButton;

import com.btr.uimeter.UIMeter;
import com.btr.uimeter.logger.UIMeterEventWriter;
import com.btr.uimeter.probes.UIMeterComponentFilter;
import com.btr.uimeter.probes.mouseclick.UIMouseClickProbe;

/*****************************************************************************
 * Helper class to work with UI meter configuration. 
 * @author Bernd Rosstauscher (java@rosstauscher.de) Copyright 2010
 ****************************************************************************/

public class UIMeterConfig {
	
	private static final String DEFAULT_LOG_FILE_NAME = "uimeter.log";

	/*************************************************************************
	 * Setup a UIMeter with default probing options.
	 ************************************************************************/
	
	public static void setupWithDefaultConfig() {
		try {
			UIMeter uiMeter = UIMeter.getInstance();
			UIMouseClickProbe probe = new UIMouseClickProbe();
			probe.addComponentFilter(new UIMeterComponentFilter() {
				public boolean accept(Component src) {
					return src instanceof AbstractButton;
				}
			});
			uiMeter.addProbe(probe);
			FileWriter logFileWriter = new FileWriter(DEFAULT_LOG_FILE_NAME);
			UIMeterEventWriter logger = new UIMeterEventWriter(logFileWriter);
			uiMeter.addProbeEventHandler(logger);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

}

